//
//  WCNewTargetOutput.m
//  WabbitCode
//
//  Created by William Towe on 3/28/09.
//  Copyright 2009 Revolution Software. All rights reserved.
//

#import "WCNewTargetOutput.h"
#import "WCNewTargetWindowController.h"


@implementation WCNewTargetOutput
- (void)dealloc {
	[_name release];
	[_templateInfo release];
	[_templateDirectory release];
	[_icon release];
	[super dealloc];
}

- (NSString *)description {
	return [NSString stringWithFormat:@"<%@>, name: %@, templateDirectory: %@, templateInfo: %@", NSStringFromClass([self class]), [self name], [self templateDirectory], [self templateInfo]];
}

@synthesize name=_name,icon=_icon,templateDirectory=_templateDirectory,templateInfo=_templateInfo;

- (NSImage *)icon {
	if (!_icon)
		return [NSImage imageNamed:@"BuildTarget48x48"];
	return _icon;
}

@dynamic shortDescription;
- (NSString *)shortDescription {
	NSString *retval = [_templateInfo objectForKey:kWCNewTargetTemplateInfoShortDescriptionKey];
	
	if (!retval)
		return NSLocalizedString(@"No long description provided",@"no long description provided for this project template");
	return retval;
}

@dynamic longDescription;
- (NSString *)longDescription {
	NSString *retval = [_templateInfo objectForKey:kWCNewTargetTemplateInfoLongDescriptionKey];
	
	if (!retval)
		return NSLocalizedString(@"No long description provided",@"no long description provided for this project template");
	return retval;
}

@dynamic targetModel;
- (NSUInteger)targetModel {
	return [[_templateInfo objectForKey:kWCNewTargetTemplateInfoTargetModelKey] unsignedIntegerValue];
}

@dynamic targetOutput;
- (NSUInteger)targetOutput {
	return [[_templateInfo objectForKey:kWCNewTargetTemplateInfoTargetOutputKey] unsignedIntegerValue];
}

@dynamic includeFiles;
- (NSArray *)includeFiles {
	return [_templateInfo objectForKey:kWCNewTargetTemplateInfoIncludeFilesKey];
}

- (id)initWithName:(NSString *)name templateInfo:(NSDictionary *)templateInfo templateDirectory:(NSString *)templateDirectory; {
	if (!(self = [super init]))
		return nil;
	
	_name = [name copy];
	_templateInfo = [templateInfo retain];
	_templateDirectory = [templateDirectory copy];
	
	NSString *iconName = [templateInfo objectForKey:kWCNewTargetTemplateInfoIconNameKey];
	if (iconName) {
		NSString *iconPath = [templateDirectory stringByAppendingPathComponent:iconName];
		if ([[NSFileManager defaultManager] fileExistsAtPath:iconPath]) {
			_icon = [[NSImage alloc] initByReferencingFile:iconPath];
		}
	}
	
	return self;
}

+ (WCNewTargetOutput *)newTargetOutputWithName:(NSString *)name templateInfo:(NSDictionary *)templateInfo templateDirectory:(NSString *)templateDirectory; {
	return [[[[self class] alloc] initWithName:name templateInfo:templateInfo templateDirectory:templateDirectory] autorelease];
}
@end
